﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Data;
using TidyBlog.Data.Mapping;

namespace TidyBlog.Entity
{
    /// <summary>
    /// 用户实体类
    /// </summary>
    [Table(Name = "TidyBlog_Article")]
    public class Article
    {
        /// <summary>
        /// 文章编号
        /// </summary>
        [Column(IsPrimaryKey = true, IsDbGenerated = true)]
        public int ArticleId { get; set; }
        /// <summary>
        /// 分类编号，负数为报纸文章，正数为分类文章
        /// </summary>
        [Column]
        public int CategoryId { get; set; }
        /// <summary>
        /// 分类名，通过触发器更新
        /// </summary>
        [Column(DataType = DbType.String, Length = 20), DisplayFormat(ConvertEmptyStringToNull = false)]
        public string CategoryName { get; set; }
        /// <summary>
        /// 作者编号
        /// </summary>
        [Column(IsUpdateIgnore = true)]
        public int AuthorId { get; set; }
        /// <summary>
        /// 作者昵称，通过触发器更新
        /// </summary>
        [Column(DataType = DbType.String, Length = 20, IsUpdateIgnore = true), DisplayFormat(ConvertEmptyStringToNull = false)]
        public string AuthorName { get; set; }
        /// <summary>
        /// 标题
        /// </summary>
        [Column(DataType = DbType.String, Length = 80), DisplayFormat(ConvertEmptyStringToNull = false)]
        public string Title { get; set; }
        /// <summary>
        /// 关键字
        /// </summary>
        [Column(DataType = DbType.String, Length = 100), DisplayFormat(ConvertEmptyStringToNull = false)]
        public string Keywords { get; set; }
        /// <summary>
        /// 摘要长度
        /// </summary>
        [Column]
        public short SummarySize { get; set; }
        /// <summary>
        /// 摘要
        /// </summary>
        [Column(DataType = DbType.String), DisplayFormat(ConvertEmptyStringToNull = false)]
        public string Summary { get; set; }
        /// <summary>
        /// 文章状态：0－私有，1－用户可查看，2－完全公开
        /// </summary>
        [Column]
        public byte State { get; set; }
        /// <summary>
        /// 内容
        /// </summary>
        [Column(DataType = DbType.String), DisplayFormat(ConvertEmptyStringToNull = false)]
        public string Content { get; set; }
        /// <summary>
        /// 查看次数
        /// </summary>
        [Column(IsDbGenerated = true, IsUpdateIgnore = true)]
        public int ViewCount { get; set; }
        /// <summary>
        /// 评论次数
        /// </summary>
        [Column(IsDbGenerated = true, IsUpdateIgnore = true)]
        public int CommentCount { get; set; }
        /// <summary>
        /// 权重
        /// </summary>
        [Column(OrderBy = 2, OrderWay = 1)]
        public byte Weight { get; set; }
        /// <summary>
        /// 发布时间
        /// </summary>
        [Column(OrderBy = 1, OrderWay = 1)]
        public DateTime PostTime { get; set; }

        /// <summary>
        /// 获取状态的文本表示
        /// </summary>
        public string StateText
        {
            get
            {
                switch (State)
                {
                    case 0: return "私有";
                    case 1: return "用户可查看";
                    case 2: return "完全公开";
                    default: return String.Empty;
                }
            }
        }
    }
}